#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read(){
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 3e5+10;
const int inf = 0x3f3f3f3f;

int f[22][N],pw[N],lg[N],ans[N],up[N],dep[N],siz[N],n,dfn[N],b[N],tim,a[N],stk[N],top;
bool cap[N];
vec G[N];
pii ner[N];

void dfs(int x,int p){
	dep[x] = dep[p] + 1; siz[x] = 1; f[0][x] = p; dfn[x] = ++tim;
	for(auto y : G[x]) if(y ^ p) dfs(y,x),siz[x] += siz[y];
}

int lca(int x,int y){
	if(dep[x] < dep[y]) swap(x,y); for(int i = lg[n];~i;i--) if(dep[f[i][x]] >= dep[y]) x = f[i][x];
	if(x == y) return x; for(int i = lg[n];~i;i--) if(f[i][x] != f[i][y]) x = f[i][x],y = f[i][y];
	return f[0][x];
}

void dfs0(int x){cap[x] = 0; up[x] = 0; for(auto y : G[x]) dfs0(y); G[x].clear();} //clear

void dfs1(int x){
	if(cap[x]) ner[x] = {0,x}; else ner[x] = {inf,0};
	for(auto y : G[x]) dfs1(y),ner[x] = min(ner[x],{ner[y].fi + dep[y] - dep[x],ner[y].se});
}

void dfs2(int x){for(auto y : G[x]) ner[y] = min(ner[y],{ner[x].fi + dep[y] - dep[x],ner[x].se}),dfs2(y);}

void dfs3(int x){
	ans[ner[x].se] += siz[x];
	for(auto y : G[x]){
		int t = y; for(int i = lg[n];~i;i--) if(dep[f[i][t]] > dep[x]) t = f[i][t];
		up[y] = t; ans[ner[x].se] -= siz[t]; dfs3(y);
	}
}

void dfs4(int x){
	for(auto y : G[x]){
		if(ner[y].se == ner[x].se) ans[ner[x].se] += siz[up[y]] - siz[y];
		else{
			int h = dep[ner[y].se] + dep[x] - ner[x].fi; h = h & 1 ? (h + 1) >> 1 : ner[x].se > ner[y].se ? h >> 1 : (h >> 1) + 1;
			int t = y; for(int i = lg[n];~i;i--) if(dep[f[i][t]] >= h) t = f[i][t];
			ans[ner[x].se] += siz[up[y]] - siz[t]; ans[ner[y].se] += siz[t] - siz[y];
		}
		dfs4(y);
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in; for(int i = 1,u,v;i < n;i++) u = in,v = in,G[u].pb(v),G[v].pb(u);
	dfs(1,0); for(int i = 2;i <= n;i++) lg[i] = lg[i >> 1] + 1; for(int i = (pw[0] = 1);i <= lg[n];i++) pw[i] = pw[i - 1] << 1;
	for(int i = 1;i <= lg[n];i++) for(int j = 1;j <= n;j++) f[i][j] = f[i - 1][f[i - 1][j]];
	for(int i = 1;i <= n;i++) G[i].clear(); int Q = in;
	while(Q--){
		int m = in; for(int i = 1;i <= m;i++) a[i] = b[i] = in,cap[a[i]] = 1;
		sort(a + 1,a + m + 1,[&](int x,int y){return dfn[x] < dfn[y];});
		stk[top = 1] = 1;
		for(int i = 1;i <= m;i++){
			if(a[i] == 1) continue;
			int x = a[i],y = lca(x,stk[top]);
			while(top > 1 && dep[stk[top - 1]] >= dep[y]) G[stk[top - 1]].pb(stk[top]),top--;
			if(stk[top] ^ y) G[y].pb(stk[top]),stk[top] = y;
			stk[++top] = x;
		}
		while(top > 1) G[stk[top - 1]].pb(stk[top]),top--;
		dfs1(1); dfs2(1); dfs3(1); dfs4(1);
		for(int i = 1;i <= m;i++) printf("%d ",ans[b[i]]),ans[b[i]] = 0;
		dfs0(1); puts("");
		//	cerr<<endl;
	}
	return 0;
}
